package com.gxa.controller;

import com.gxa.exception.CustomerException;
import com.gxa.pojo.Theme;
import com.gxa.service.ThemeService;
import com.gxa.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 伍炳清
 * @date 2020-09-25 19:27
 */
@Controller
@RequestMapping("/theme")

public class ThemeController {
    @Resource
    private ThemeService themeService;
    JsonResult jsonResult = new JsonResult();

    //查找所有诊疗项目
    @PostMapping(value = "/findAll")
    @ResponseBody
    public Map findAll() {

        try {
            List<Theme> allTheme = themeService.findAllTheme();
            jsonResult.setCode("200");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(allTheme);

        } catch (Exception e) {
            jsonResult.setCode("500");
            jsonResult.setMsg("查询失败");
        }

        return jsonResult.getValues();
    }
    //通过id查找诊疗项目
    @PostMapping(value = "/findThemeById")
    @ResponseBody
    public Map findThemeById(@PathVariable("id") Integer id) {

        try {

            Theme themeById = themeService.findThemeById(id);
            jsonResult.setCode("200");
            jsonResult.setMsg("查询成功");
            jsonResult.setData(themeById);

        } catch (Exception e) {

            jsonResult.setCode("500");
            jsonResult.setMsg("查询失败");
        }

        return jsonResult.getValues();
    }
}
